package TestFiles;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import graphdisplay.*;

import javax.swing.*;

public class DisplayUSMap extends JFrame {

    static private Graph<City> graph;
    static private GraphView graphView;

    public DisplayUSMap(int[][] edges, City[] vertices) {
    }

    public DisplayUSMap(List<AbstractGraph.Edge> edgeslist, List<City> verticeslist) {

        graph = new UnweightedGraph<City>(edgeslist, verticeslist);
        graphView = new GraphView(graph);
        add(graphView);
        // TODO Auto-generated constructor stub
    }

    static class City implements Displayable {

        private int x, y;
        private String name;

        City(String name, int x, int y) {
            this.name = name;
            this.x = x;
            this.y = y;
        }

        public int getX() {
            return x;
        }

        public int getY() {
            return y;
        }

        public String getName() {
            return name;
        }
    }

    public static void main(String[] args) {

        List<City> verticeslist = new ArrayList<City>();


        verticeslist.add(new City("Seattle", 75, 50));
        verticeslist.add(new City("San Francisco", 50, 210));
        verticeslist.add(new City("Los Angeles", 75, 275));
        verticeslist.add(new City("Denver", 275, 175));
        verticeslist.add(new City("Kansas City", 400, 245));
        verticeslist.add(new City("Chicago", 450, 100));
        verticeslist.add(new City("Boston", 700, 80));
        verticeslist.add(new City("New York", 675, 120));
        verticeslist.add(new City("Atlanta", 575, 295));
        verticeslist.add(new City("Miami", 600, 400));
        verticeslist.add(new City("Dallas", 408, 325));
        verticeslist.add(new City("Houston", 450, 360));



        List<AbstractGraph.Edge> edgeslist = new ArrayList<AbstractGraph.Edge>();
        // Edge array for graph in Figure 27.1
        edgeslist.add(new AbstractGraph.Edge(0, 1));
        edgeslist.add(new AbstractGraph.Edge(0, 3));
        edgeslist.add(new AbstractGraph.Edge(0, 5));

        edgeslist.add(new AbstractGraph.Edge(1, 0));
        edgeslist.add(new AbstractGraph.Edge(1, 2));
        edgeslist.add(new AbstractGraph.Edge(1, 3));

        edgeslist.add(new AbstractGraph.Edge(2, 1));
        edgeslist.add(new AbstractGraph.Edge(2, 3));
        edgeslist.add(new AbstractGraph.Edge(2, 4));
        edgeslist.add(new AbstractGraph.Edge(2, 10));

        edgeslist.add(new AbstractGraph.Edge(3, 0));
        edgeslist.add(new AbstractGraph.Edge(3, 1));
        edgeslist.add(new AbstractGraph.Edge(3, 2));
        edgeslist.add(new AbstractGraph.Edge(3, 4));
        edgeslist.add(new AbstractGraph.Edge(3, 5));

        edgeslist.add(new AbstractGraph.Edge(4, 2));
        edgeslist.add(new AbstractGraph.Edge(4, 3));
        edgeslist.add(new AbstractGraph.Edge(4, 5));
        edgeslist.add(new AbstractGraph.Edge(4, 7));
        edgeslist.add(new AbstractGraph.Edge(4, 8));
        edgeslist.add(new AbstractGraph.Edge(4, 10));

        edgeslist.add(new AbstractGraph.Edge(5, 0));
        edgeslist.add(new AbstractGraph.Edge(5, 3));
        edgeslist.add(new AbstractGraph.Edge(5, 4));
        edgeslist.add(new AbstractGraph.Edge(5, 6));
        edgeslist.add(new AbstractGraph.Edge(5, 7));

        edgeslist.add(new AbstractGraph.Edge(6, 5));
        edgeslist.add(new AbstractGraph.Edge(6, 7));

        edgeslist.add(new AbstractGraph.Edge(7, 4));
        edgeslist.add(new AbstractGraph.Edge(7, 5));
        edgeslist.add(new AbstractGraph.Edge(7, 6));
        edgeslist.add(new AbstractGraph.Edge(7, 8));

        edgeslist.add(new AbstractGraph.Edge(8, 4));
        edgeslist.add(new AbstractGraph.Edge(8, 7));
        edgeslist.add(new AbstractGraph.Edge(8, 9));
        edgeslist.add(new AbstractGraph.Edge(8, 10));
        edgeslist.add(new AbstractGraph.Edge(8, 11));

        edgeslist.add(new AbstractGraph.Edge(9, 8));
        edgeslist.add(new AbstractGraph.Edge(9, 11));

        edgeslist.add(new AbstractGraph.Edge(10, 2));
        edgeslist.add(new AbstractGraph.Edge(10, 4));
        edgeslist.add(new AbstractGraph.Edge(10, 8));
        edgeslist.add(new AbstractGraph.Edge(10, 11));

        edgeslist.add(new AbstractGraph.Edge(11, 8));
        edgeslist.add(new AbstractGraph.Edge(11, 9));
        edgeslist.add(new AbstractGraph.Edge(11, 10));



//        JFrame frame = new JFrame("DisplayUSMap");
//        DisplayUSMap applet = new DisplayUSMap(edgeslist, verticeslist);
//        frame.add(applet);
//        //applet.init();
//        //applet.start();
//        frame.setLocationRelativeTo(null);
//        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//        frame.setSize(800, 500);
//        frame.setVisible(true);
        
        //JFrame frame = new JFrame("DisplayUSMap");
        DisplayUSMap applet = new DisplayUSMap(edgeslist, verticeslist);
        applet.setLocationRelativeTo(null);
        applet.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        applet.setSize(800, 500);
        applet.setVisible(true);

        Scanner scan = new Scanner(System.in);
        int i = 0;
        int result = 0;
        while (result != 3) {

            System.out.println("Select what do u want from the Menu");
            System.out.println();
            System.out.println();
            System.out.println("Select 1. for creation of a node");
            System.out.println("Select 2. for creating an edge");
            System.out.println("Select 3. for exit");
            result = scan.nextInt();

            switch (result) {
                case 1:
                    String cityname;
                    int x,
                     y;
                    System.out.println("for creating node enter city name,x-position,y-position:");
                    System.out.println("Enter the City Name:");
                    cityname = scan.next();
                    System.out.println("Enter the positions x and Y for the city :" + cityname);
                    x = scan.nextInt();
                    y = scan.nextInt();



                    //frame.remove(applet);
                    verticeslist.add(new City(cityname, x, y));
                    graph = new UnweightedGraph<City>(edgeslist, verticeslist);
                    graphView.setGraph(graph);
                    //graphView.repaint();
                    //applet = new DisplayUSMap(edgeslist, verticeslist);
                    //frame.add(applet);
                    //applet.init();
                    //applet.start();
                    //frame.setVisible(true);
                    break;


                case 2:
                    int startnodes,
                     endnodes;
                    System.out.println("Enter the Starting node id between 0&" + (verticeslist.size() - 1) + "=");
                    startnodes = scan.nextInt();
                    System.out.print("Enter the Ending node idbetween 0&" + (verticeslist.size() - 1) + "=");
                    endnodes = scan.nextInt();

                    edgeslist.add(new AbstractGraph.Edge(startnodes, endnodes));

//                    frame.remove(applet);
//
//                    applet = new DisplayUSMap(edgeslist, verticeslist);
//                    frame.add(applet);
//                    //applet.init();
//                    //applet.start();
//                    frame.setVisible(true);
                    break;



                case 3:

                    result = 3;

                    break;

                default:
                    System.out.println("Invalid Entry!" + "Enter in between 1&3");
            }


        }

    }
}